package cn.usbtg.common.idmanager.formater;

import java.util.Random;

/**
 * 常量格式化器：
 * 获取一个从min到max的常量；
 * 当未指定min时，min的值为与max相同长度位数的最小整数
 */
public class RandomIntFormater extends BasicFormater {
    protected int min;
    protected int max;

    public RandomIntFormater(int max) {
        int log10 = (int) Math.log10(max);
        this.min = log10 == 0 ? 0 : (int) Math.pow(10, log10);
        this.max = max;
    }

    public RandomIntFormater(int min, int max) {
        this.min = min;
        this.max = max;
    }

    @Override
    public String next(Object... params) {
        return super.last = String.valueOf(new Random().nextInt(max) % (max - min + 1) + min);
    }

    public int getMin() {
        return min;
    }

    public void setMin(int min) {
        this.min = min;
    }

    public int getMax() {
        return max;
    }

    public void setMax(int max) {
        this.max = max;
    }
}